import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:"/home"
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    meta:{
      footshow:true,
      playshow:true
    }
  },
  {
    path: '/find',
    name: 'find',
    meta:{
      footshow:true,
      playshow:true
    },
    component: () => import('../views/findView.vue')
  },
  {
    path: '/vip',
    name: 'vip',
    meta:{
      footshow:true,
      playshow:true
    },
    component: () => import('../views/vipView.vue')
  },
  {
    path: '/my',
    name: 'my',
    meta:{
      footshow:true,
      playshow:true
    },
    component: () => import('../views/myView.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/searchView.vue')
  },
  {
    path: '/homeType',
    name: 'homeType',
    meta:{
      playshow:true
    },
    component: () => import('../views/homeType.vue')
  },
  {
    path: '/collection',
    name: 'collection',
    meta:{
      playshow:true
    },
    component: () => import('../views/collectionView.vue')
  },
  {
    path: '/down',
    name: 'down',
    meta:{
      playshow:true
    },
    component: () => import('../views/downView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/loginView.vue')
  },

  {
    path: '/classification',
    name: 'classification',
    component: () => import('../views/classificationView.vue')
  },
  {
    path: '/searchResult',
    name: 'searchResult',
    meta:{
      playshow:true
    },
    component: () => import('../views/searchResult.vue')
  },
  {
    path: '/findList',
    name: 'findList',
    meta:{
      playshow:true
    },
    component: () => import('../views/findList.vue')
  },
  {
    path: '/aboutMy',
    name: 'aboutMy',
    meta:{
      playshow:true
    },
    component: () => import('../views/aboutMy.vue')
  },
  {
    path: '/help',
    name: 'help',
    meta:{
      playshow:true
    },
    component: () => import('../views/helpView.vue')
  },
  {
    path: '/agreement',
    name: 'agreement',
    meta:{
      playshow:true
    },
    component: () => import('../views/agreementView.vue')
  },
  {
    path: '/privacy',
    name: 'privacy',
    meta:{
      playshow:true
    },
    component: () => import('../views/privacyView.vue')
  },
  {
    path: '/playHistory',
    name: 'playHistory',
    meta:{
      playshow:true
    },
    component: () => import('../views/playHistory.vue')
  },
  {
    path: '/member',
    name: 'member',
    meta:{
      playshow:false
    },
    component: () => import('../views/memberView.vue'),
    beforeEnter:(to,from,next)=>{
      let token =window.localStorage.getItem("token");
      // 判断是否登陆
      if(!token){
        next("/login");
        return;
      }else{
        next();
      }
    }
  },
]


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err);
}


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
